﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class AMSTAMMController : ITXController
    { 
        public ActionResult MYB(string returnUrl)
        {
            ModelState.Clear();
            if (!MABF.IsAMRunReady)
            {
                AMSTAMMModel model = new AMSTAMMModel();
                model.MACHINEID = "46";
                AMCHK(model);
                StartMonitoring(MABF.MAM);
            }
            ViewBag.ReturnUrl = returnUrl;
            return PartialView(MABF.MAM);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult MYB(AMSTAMMModel model, string returnUrl)
        {
            MABF.MAM.VU0 = MABF.MAM.UIAM.VU0;
            MABF.MAM.VU1 = MABF.MAM.UIAM.VU1;
            return PartialView(MABF.MAM);
        }
        [ChildActionOnly]
        public ActionResult MZLYBJ(string returnUrl)
        {
            ModelState.Clear();
            if (!MABF.IsAMRunReady)
            {
                StartMonitoring(MABF.MAM);
            }
            ViewBag.ReturnUrl = returnUrl;
            return PartialView(MABF.MAM);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult MZLYBJ(AMSTAMMModel model, string returnUrl)
        {
            MABF.MAM.VU0 = MABF.MAM.UIAM.VU0;
            MABF.MAM.VU1 = MABF.MAM.UIAM.VU1;
            return PartialView(MABF.MAM);
        }
        public void StartMonitoring(AMSTAMMModel model)
        {
            if (TAMClient == null)
            {
                return;
            }
            VAMSTAMM UIAM = new VAMSTAMM();
            string key = MABF.MAM.MKRS + MABF.MAM.MLFD + MABF.MAM.MPOS;
            TAMClient.MachinesLib[key] = UIAM;
            TAMClient.Register("REG", key, UIAM);
            TAMClient.Register("SIMULATE", key, UIAM);
            MABF.MAM.UIAM = UIAM;
            MABF.MAM.IsAMRunReady = true;
            MABF.IsAMRunReady = MABF.MAM.IsAMRunReady;
            INFO = "已开始监控";
        }
        public ActionResult Search(string query, int? page)
        {
           
            if (Request.IsAjaxRequest())
            {
                MABF.MAM.VU0 = MABF.MAM.UIAM.VU0;
                MABF.MAM.VU1 = MABF.MAM.UIAM.VU1;
                ViewData["VU0"] = MABF.MAM.UIAM.VU0; 
                return View("MZLYBJ", MABF.MAM);
            }
            else
            {
                return View();
            }
        }

    }
}
